﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Threading;

namespace ECGServer
{
    class ThreadManageConnection
    {
        public ThreadManageConnection()
        {            
        }

        public void run()
        {
            Thread thread = new Thread(new ThreadStart(check));
            thread.Start();
        }

        public void check()
        {
            while (true)
            {
                DateTime datetime = System.DateTime.Now;
                if (ECGServer.PID_WorkStation.Count != 0)
                {
                    foreach (DictionaryEntry Item in ECGServer.PID_WorkStation)
                    {
                        WorkStation ws = (WorkStation)Item.Value;
                        if ((ws.LastCommunicationTime - datetime).Milliseconds == 3000)
                        {
                            lock (ECGServer.PID_WorkStation)
                            {
                                ECGServer.PID_WorkStation.Remove(Item.Key);
                            }
                        }
                    }
                }
                Thread.Sleep(3000);
            }
        }
    }
}
